package com.punai.customer.controller;

import cn.hutool.core.util.StrUtil;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.customer.domain.CusFeature;
import com.punai.customer.domain.bo.CusLinkFeatureBo;
import com.punai.customer.domain.vo.CusLinkFeatureVo;
import com.punai.customer.service.ICusFeatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 特征Controller
 * 
 * @author ruoyi
 * @date 2022-12-04
 */
@RestController
@RequestMapping("/cus/feature")
public class CusFeatureController extends BaseController
{
    @Autowired
    private ICusFeatureService cusFeatureService;

    @GetMapping(value = "/getByNameSearch/{name}/{type}")
    public AjaxResult getByNameSearch(@PathVariable("name") String name, @PathVariable("type") String type)
    {
        if (StrUtil.isEmpty(name)) {
            return AjaxResult.success(new ArrayList<>());
        }
        CusFeature cusFeature = new CusFeature();
        cusFeature.setFeatureName(name);
        cusFeature.setType(type);
        cusFeature.setCompanyId(getCompanyId());
        List<CusFeature> nameSearch = cusFeatureService.getByNameSearch(cusFeature);
        return AjaxResult.success(nameSearch);
    }

    @GetMapping(value = "/getChildById/{id}")
    public AjaxResult getChildById(@PathVariable("id") String id)
    {
        CusLinkFeatureBo featureBo = cusFeatureService.getChildById(id);
        return AjaxResult.success(featureBo);
    }

    @GetMapping(value = "/getFeatureListByChapterId")
    public AjaxResult getFeatureListByChapterId(CusLinkFeatureVo cusLinkFeatureVo)
    {
        return AjaxResult.success(cusFeatureService.getFeatureListByChapterId(cusLinkFeatureVo));
    }
}
